#include<iostream>
#include<string>
using namespace std;
int main(){
	int n = 0,m ,t,k;
	string s1,s2;
	cin >> n >> s1;
	while(n--){
		cin >> m;
		switch(m){
			case 1: cin >> s2; s1+= s2;cout << s1 <<endl;break;
			case 2: cin >> t >> k; s1 = s1.substr(t,k);cout <<s1<<endl;break; 
			case 3: cin >> t >> s2; s1.insert(t,s2);cout << s1 << endl;break;
			case 4: cin >> s2; size_t h = s1.find(s2);
			if(h == string::npos) cout << "-1" << endl;
			else cout << h << endl;
			break;
		}
	}
	return 0;
}
